Welcome Guest | Sign in | Register

Home > C Programming > If statements > Questions and Answers

01. What is the output of following C code?
main()
{
float me = 1.1;
double you = 1.1;
if(me==you)
printf("I love U");
else
printf("I hate U");
}
A. I hate U B. I love U
C. Compiler error D. None of these

Answer and Explanation

Answer: I hate U

Explanation:
For floating point numbers (float, double, long double) the values cannot be predicted exactly.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
02. What is the output of following C code?
main()
{
static int var = 5;
printf("%d ",var--);
if(var)
main();
}
A. 5 4 3 2 1 B. 4 3 2 1
C. 3 2 1 D. 5 4 3 2
E. 5 4 3 2 1 0

Answer and Explanation

Answer: 5 4 3 2 1

Explanation:
When static storage class is given, it is initialized once. The change in the value of a static variable is retained even between the function calls. Main is also treated like any other ordinary function, which can be called recursively.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
03. What is the output of following C code?
main()
{
int a= 0;int b = 20;char x =1;char y =10;
if(a,b,x,y)
printf("hello");
}
A. 0 B. 10
C. hello D. 1

Answer and Explanation

Answer: hello

Explanation:
The comma operator has associativity from left to right. Only the rightmost value is returned and the other values are evaluated and ignored. Thus the value of last variable y is returned to check in if. Since it is a non zero value if becomes true so, "hello" will be printed.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
04. What is the output of following C code?
#ifdef something
int some=0;
#endif

main()
{
int thing = 0;
printf("%d %d\n", some ,thing);
}
A. 0 0 B. 0
C. null D. Compiler error

Answer and Explanation

Answer: Compiler error

Explanation:
This is a very simple example for conditional compilation. The name something is not already known to the compiler making the declaration int some = 0; effectively removed from the source code.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
05. Which of the following is the boolean operator for logical-and?
A. & B. &&
C. | D. |&

Answer and Explanation

Answer: &&

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
06. Evaluate !(1 && !(0 || 1)).
A. True B. False
C. Compile Error D. Cannot be determined

Answer and Explanation

Answer: True

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
07. Which of the following shows the correct syntax for an if statement?
A. if expression B. if { expression
C. if ( expression ) D. expression if

Answer and Explanation

Answer: if ( expression )

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
08. The statement that tests to see if sum is equal to 10 and total is less than 20, and if so, prints the text string "incorrect.", is
A. Statement 1
if( (sum = 10) && (total < 20) )
printf("incorrect.");
B. Statement 2
if( (sum == 10) && (total < 20) )
printf("incorrect.");
C. Statement 3
if( (sum == 10) || (total < 20) )
printf("incorrect.");
D. Cannot be determined

Answer and Explanation

Answer: Statement 2
if( (sum == 10) && (total < 20) )
printf("incorrect.");

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
09. If flag is 1 or letter is not an 'X', then assign the value 0 to exit_flag, else set exit_flag to 1.
A. Statement 1
if( (flag = 1) || (letter != 'X') )
exit_flag = 0;
else
exit_flag = 1;
B. Statement 2
if( (flag == 1) || (letter <> 'X') )
exit_flag = 0;
else
exit_flag = 1;
C. Statement 3
if( (flag == 1) || (letter != 'X') )
exit_flag = 0;
else
exit_flag = 1;
D. Cannot be determined

Answer and Explanation

Answer: Statement 3
if( (flag == 1) || (letter != 'X') )
exit_flag = 0;
else
exit_flag = 1;

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
10. The statement that compares the value of an integer called sum against the value 65, and if it is less, prints the text string "Sorry, try again", is
A. Statement 1
if( sum < "65" )
printf("Sorry, try again" );
B. Statement 2
if( sum <= 65 )
printf("Sorry, try again" );
C. Statement 3
if( 65 == sum )
printf("Sorry, try again" );
D. Statement 4
if( sum < 65 )
printf("Sorry, try again" );

Answer and Explanation

Answer: Statement 4
if( sum < 65 )
printf("Sorry, try again" );

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum



Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.